package com.example.controller;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.example.user.common.UserInfo;

@RestController
@RequestMapping("/user")
public class UserController {

	@Value("${server.port:serverPortUnknown}")
	private String serverPort;

	@GetMapping("/list")
	public List<UserInfo> list() {
		List<UserInfo> retList = new ArrayList<>();
		// 这个字段用于测试，标识是哪个微服务响应请求的
		String desc = "";
		InetAddress ia;
		try {
			ia = InetAddress.getLocalHost();
			desc += ia.getHostAddress() + " ";
			desc += ia.getHostName() + " ";
			desc += serverPort + " ";
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}

		UserInfo user1 = new UserInfo();
		user1.setUserId("123");
		user1.setUserName(desc);
		retList.add(user1);
		return retList;
	}

}
